import request from './request'
import { useUserStore } from '../store/modules/user'
// 工单模块下拉列表查询
export function workModulePageSelect(data: { limit: number; keyword: any; page: number }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/work/getWorkModuleSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 工单级别下拉列表查询
export function workLevelPageSelect(data: { limit: number; keyword: any; page: number }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/work/getWorkLevelSelect',
    method: 'post',
    headers: token,
    data,
  })
}
//根据模块ID获取工单自定义字段
export function getModuleField(id: string) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/work/getWorkModuleFieldSelect/' + id,
    method: 'get',
    headers: token,
  })
}

// 获取报单商品品牌下拉数据
export function getOrderBrandSelect(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/goods/getOrderBrandSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据品牌ID获取报单商品分类下拉数据
export function getOrderGoodsTypeSelect(data, id) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/goods/getOrderGoodsTypeSelect/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据品牌ID&商品分类ID获取报单商品下拉数据
export function getOrderGoodsSelect(data, brandId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: `/select/goods/getOrderGoodsSelect/${brandId}`,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据产品ID获取报单商品规格下拉数据
export function getOrderGoodsSpecSelect(productId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: `/select/goods/getOrderGoodsSpecSelect/${productId}`,
    method: 'get',
    headers: token,
  })
}
// 获取创建工单的商家及账户余额
export function getCreateOrderBalance() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/factory/getCreateOrderBalance',
    method: 'get',
    headers: token,
  })
}

// 创建或修改工单保存
export function addSave(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/saveOrder',
    method: 'post',
    headers: token,
    data,
  })
}
// 用户联系人下拉数据列表
export function getUserSelect(data: { limit: number; keyword: any; page: number }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/user/select/getOrderUserSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取工单列表
export function getOrderList(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getList',
    method: 'post',
    headers: token,
    data,
  })
}
//获取工单列表状态数量
export function getOrderStatusQty() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderStatusQty',
    method: 'get',
    headers: token,
  })
}

//获取工单列表搜索条件的工单自定义搜索字段
export function getOrderListSelectField() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderListCustomSearchField',
    method: 'get',
    headers: token,
  })
}
// 获取工单列表表头的工单自定义字段
export function getOrderListTableTitleField() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderListTableField',
    method: 'get',
    headers: token,
  })
}
// 工单催单
export function saveReminder(data: { remark: string; workIds: unknown[] }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/reminder/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 工单备注
export function saveRemark(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/remark/save',
    method: 'post',
    headers: token,
    data,
  })
}
//工单取消
export function cancelOrder(data: { remark: string; workIds: unknown[] }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/cancelOrder',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据工单ID获取工单商品
export function getOrderGoodsDetail(data, workId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderGoods/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据工单ID获取工单详情{id}
export function getOrderDetail(id: string | string[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderDetail/' + id,
    method: 'get',
    headers: token,
  })
}
//根据工单ID获取工单操作记录列表
export function getOrderLog(data: { limit: number; page: number }, workId: string | unknown[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderLog/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// *******************************自定义表头**************

// 获取工单列表表头字段
export function getOrderListTableField(type) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/table/field/getOrderListTableField/' + type,
    method: 'get',
    headers: token,
  })
}
// 获取工单表头字段设置项
export function getOrderTableField(type) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/table/field/getOrderTableField/' + type,
    method: 'get',
    headers: token,
  })
}
// 保存或更新工单表头字段
export function workTableFieldSave(data, type) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/table/field/save/' + type,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取工单列表排序字段设置
export function getOrderTableOrderByField(type) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/by/field/getOrderTableOrderByField/' + type,
    method: 'get',
    headers: token,
  })
}
// 新增或修改工单列表排序字段
export function orderBySave(data, type) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/by/field/save/' + type,
    method: 'post',
    headers: token,
    data,
  })
}

//获取工单表头初始化字段
export function getOrderTableInitField() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/table/field/getOrderTableInitField',
    method: 'get',
    headers: token,
  })
}
//获取工单列表排序初始化字字段
export function getOrderTableInitOrderByField() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/by/field/getOrderTableInitOrderByField',
    method: 'get',
    headers: token,
  })
}
// *****************end**********************
// 根据工单ID获取服务项目列表
export function getOrderDetailFeeProjectList(data: any, workId: string | string[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/getOrderDetailFeeList/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取工单详情的工单配件列表
export function getOrderDetailWorkSpareList(data: any, workId: string | string[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/spare/getOrderDetailWorkSpareList/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}

// 根据工单ID获取工单备注列表
export function getRemarkList(data: { limit: number; page: number }, workId: string | unknown[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderRemark/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据工单ID获取工单催单列表
export function getReminderList(data: { limit: number; page: number }, workId: string | unknown[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/reminder/getList/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
//获取工单详情的应付费用
export function getPaymentFee(workId: string | unknown[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getPaymentFee/' + workId,
    method: 'get',
    headers: token,
  })
}
//获取工单详情的服务费用详情
export function getOrderFeeDetail(id) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/getFeeDetail/' + id,
    method: 'get',
    headers: token,
  })
}
// 获取服务费用的费用项信息
export function OrderFeeDetailProjectInfo(id: string) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/getFeeDetailFeeInfos/' + id,
    method: 'get',
    headers: token,
  })
}
// 获取服费用项目日志列表
export function getOrderFeeLogList(data, id) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/getOrderFeeLogList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取商家工单费用权限
export function getFeeAuthori() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/factory/getFeeAuthori',
    method: 'get',
    headers: token,
  })
}
// 获取商家工单配件权限
export function getSpareAuthori() {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/factory/getSpareAuthori',
    method: 'get',
    headers: token,
  })
}

// 根据工单ID获取工单信息
export function getOrderParamField(workId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getOrderParamField/' + workId,
    method: 'get',
    headers: token,
  })
}

// 用户联系人下拉数据列表
export function userSelect(data: { limit: number; name: any; page: number }, userId: string) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/select/user/' + userId,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取工单报单产品
export function getOrderProduct(data: {
  brandId: any
  keyword: string
  limit: any
  page: any
  typeId: any
}) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/goods/product/getOrderProduct',
    method: 'post',
    headers: token,
    data,
  })
}
// 批量更新工单流程为完成
export function finishOrder(data: { remark: string; workIds: unknown[] }) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/finishOrder',
    method: 'put',
    headers: token,
    data,
  })
}

//根据工单ID获取工单留言
export function getWorkLeaveMessageList(
  data: { limit: number; page: number },
  workId: string | unknown[],
) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getWorkLeaveMessageList/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// 保存工单留言
export function saveWorkLeaveMessage(data: {
  annex: any[]
  content: string
  visitTypes: number
  workId: string | unknown[]
}) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/saveWorkLeaveMessage',
    method: 'post',
    headers: token,
    data,
  })
}

// 根据工单ID获取服务商信息
export function getServiceInfo(workId: string | string[]) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/order/getServiceInfo/' + workId,
    method: 'get',
    headers: token,
  })
}

// 获取工单服务费用项目列表
export function feeWork(data: {
  applyEmp: string
  createEndTime: string
  createStartTime: string
  feeNo: string
  limit: number
  page: number
  status: any
  workNo: string
}) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/getList',
    method: 'post',
    headers: token,
    data,
  })
}

// 审核工单服务费用项目
export function checkOrderFee(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/checkOrderFee',
    method: 'post',
    headers: token,
    data,
  })
}
// 保存或修改工单服务费用
export function feeSaveOrder(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/work/fee/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 工单费用项目下拉列表查询
export function workFeeProjectPageSelect(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/order/select/workFeeProjectPageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 分页获取工单配件下拉数据列表
export function getOrderSparePageSelect(data, workId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/order/select/getOrderSparePageSelect/' + workId,
    method: 'post',
    headers: token,
    data,
  })
}
// 分页获取工单配件规格下拉数据列表
export function getOrderSpareSpecSelect(data, spareId) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/order/select/getOrderSpareSpecSelect/' + spareId,
    method: 'post',
    headers: token,
    data,
  })
}

//工单模块带费用下拉列表查询
export function workModulePricePageSelect(data) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: '/order/select/workModulePricePageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

/**
 * 根据工单ID获取结单字段
 * @param {String} id - 工单id
 */
export function getOrderSettleInfoByOrderId(id: string) {
  const token = {
    [useUserStore().row.tokenName]: useUserStore().token,
  }
  return request({
    url: `/work/order/getOrderSettlementField/${id}`,
    method: 'get',
    headers: token,
  })
}
